from baseconfig import BaseConfig

class Config(BaseConfig):

    def __init__(self):
        '''
        Load the main configuration file (main.conf)
        '''
        BaseConfig.__init__(self, 'main')
        self.screen_size = [320, 240]
        self.channels = self._parse_channels()
        self.tv_command = self._get_tv_command()
    
    def _parse_channels(self):
        '''Construct channel options for mplayer command, -tv flag'''
        o, u = '', []
        for i in range(0, len(self.get_conf('channels'))):
            c = self.get_conf(['channels', str(i+1)])
            if o != '':
                o += ','
            o += '%s-%s' % (c[1], c[0])
            u.append([c[1], c[0]])
        return o, u
    
    def _get_tv_command(self):
        '''
        Construct mplayer command for -tv flag
        '''
        c = 'mplayer -vo %s -cache %s ' % (self.get_conf('video_out'), self.get_conf('cache'))
        if self.get_conf('framedrop'):
            c += '-framedrop '
        c+= 'tv:// -tv device=%s:%s:channels=%s' % (self.get_conf('tv_card'), self.get_conf('tv_opts'), self.channels[0])
        return c
